/*
 * @轮子的作者: 轮子哥
 * @Date: 2023-08-29 15:34:18
 * @LastEditTime: 2023-12-05 11:44:29
 */
const { defineConfig } = require('@vue/cli-service')
let config = require('./src/config.js')

//element plus按需自动引用
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = defineConfig({
  transpileDependencies: true,
  assetsDir: 'static',
  parallel: false,
  publicPath: './',
  productionSourceMap: false,//关闭生产环境的Source Map
  configureWebpack: {
    optimization: {
      usedExports: true, //只导出被使用的模块
      minimize : true // 启动压缩
    },
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),

      // 配置webpack 打包压缩
      new CompressionWebpackPlugin({
        test: /\.js$|\.html$|\.css$/,
        threshold: 4024
      }),

      //包构建分析
      // new BundleAnalyzerPlugin({
      //   openAnalyzer: true
      // }),
      // new DllPlugin({  
      //   entry: {  
      //     vendor: ['lodash', 'react', 'react-dom'],  
      //   },  
      //   output: {  
      //     path: path.resolve(__dirname, 'dist/dll'),  
      //     filename: '[name].dll.js',  
      //     library: '[name]',  
      //   },  
      // }),  
    ],
    //苹果地图全局挂载
    externals: {
      'mapkit.js': 'window.mapkit'
    }
  },

  // 跨域配置
  transpileDependencies: true,
  devServer: {
    port: 9528,
    proxy: {
      '/api': {
        target: config.api[0].apiUrl,
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        },
      },
    }
  },


})

